home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / CIncludes / Serial.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  9.9 KB  |  327 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        Serial.h
  3.  
  4.      Contains:    Asynchronous Serial Driver (.AIn/.AOut/.BIn/.BOut) Interfaces
  5.  
  6.      Version:    Technology:    System 7.6+
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1985-1998 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __SERIAL__
  18. #define __SERIAL__
  19.  
  20. #ifndef __MACTYPES__
  21. #include <MacTypes.h>
  22. #endif
  23.  
  24.  
  25.  
  26. #if PRAGMA_ONCE
  27. #pragma once
  28. #endif
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. #if PRAGMA_IMPORT
  35. #pragma import on
  36. #endif
  37.  
  38. #if PRAGMA_STRUCT_ALIGN
  39.     #pragma options align=mac68k
  40. #elif PRAGMA_STRUCT_PACKPUSH
  41.     #pragma pack(push, 2)
  42. #elif PRAGMA_STRUCT_PACK
  43.     #pragma pack(2)
  44. #endif
  45.  
  46.  
  47. enum {
  48.     baud150                        = 763,
  49.     baud300                        = 380,
  50.     baud600                        = 189,
  51.     baud1200                    = 94,
  52.     baud1800                    = 62,
  53.     baud2400                    = 46,
  54.     baud3600                    = 30,
  55.     baud4800                    = 22,
  56.     baud7200                    = 14,
  57.     baud9600                    = 10,
  58.     baud14400                    = 6,
  59.     baud19200                    = 4,
  60.     baud28800                    = 2,
  61.     baud38400                    = 1,
  62.     baud57600                    = 0
  63. };
  64.  
  65.  
  66. enum {
  67.     stop10                        = 16384,
  68.     stop15                        = -32768L,
  69.     stop20                        = -16384
  70. };
  71.  
  72.  
  73. enum {
  74.     noParity                    = 0,
  75.     oddParity                    = 4096,
  76.     evenParity                    = 12288
  77. };
  78.  
  79.  
  80. enum {
  81.     data5                        = 0,
  82.     data6                        = 2048,
  83.     data7                        = 1024,
  84.     data8                        = 3072
  85. };
  86.  
  87.  
  88. enum {
  89.     aData                        = 6,                            /* channel A data in or out (historical) */
  90.     aCtl                        = 2,                            /* channel A control (historical) */
  91.     bData                        = 4,                            /* channel B data in or out (historical) */
  92.     bCtl                        = 0                                /* channel B control (historical) */
  93. };
  94.  
  95.  
  96. enum {
  97.     dsrEvent                    = 2,                            /* flag for SerShk.evts */
  98.     riEvent                        = 4,                            /* flag for SerShk.evts */
  99.     dcdEvent                    = 8,                            /* flag for SerShk.evts */
  100.     ctsEvent                    = 32,                            /* flag for SerShk.evts */
  101.     breakEvent                    = 128                            /* flag for SerShk.evts */
  102. };
  103.  
  104.  
  105. enum {
  106.     xOffWasSent                    = 128,                            /* flag for SerStaRec.xOffSent */
  107.     dtrNegated                    = 64,                            /* flag for SerStaRec.xOffSent */
  108.     rtsNegated                    = 32                            /* flag for SerStaRec.xOffSent */
  109. };
  110.  
  111.  
  112. enum {
  113.     ainRefNum                    = -6,                            /* serial port A input */
  114.     aoutRefNum                    = -7,                            /* serial port A output */
  115.     binRefNum                    = -8,                            /* serial port B input */
  116.     boutRefNum                    = -9                            /* serial port B output */
  117. };
  118.  
  119.  
  120. enum {
  121.     swOverrunErr                = 1,                            /* serial driver error masks */
  122.     breakErr                    = 8,                            /* serial driver error masks */
  123.     parityErr                    = 16,                            /* serial driver error masks */
  124.     hwOverrunErr                = 32,                            /* serial driver error masks */
  125.     framingErr                    = 64                            /* serial driver error masks */
  126. };
  127.  
  128.  
  129. enum {
  130.     kOptionPreserveDTR            = 128,                            /* option bit used with Control code 16 */
  131.     kOptionClockX1CTS            = 64                            /* option bit used with Control code 16 */
  132. };
  133.  
  134.  
  135. enum {
  136.     kUseCTSOutputFlowControl    = 128,                            /* flag for SerShk.fCTS */
  137.     kUseDSROutputFlowControl    = 64,                            /* flag for SerShk.fCTS */
  138.     kUseRTSInputFlowControl        = 128,                            /* flag for SerShk.fDTR */
  139.     kUseDTRInputFlowControl        = 64                            /* flag for SerShk.fDTR */
  140. };
  141.  
  142.  
  143. enum {
  144.     sPortA                        = 0,                            /* Macintosh modem port */
  145.     sPortB                        = 1,                            /* Macintosh printer port */
  146.     sCOM1                        = 2,                            /* RS-232 port COM1 */
  147.     sCOM2                        = 3                                /* RS-232 port COM2 */
  148. };
  149.  
  150. typedef SInt8                             SPortSel;
  151. /* csCodes for serial driver Control routines */
  152.  
  153. enum {
  154.     kSERDConfiguration            = 8,                            /* program port speed, bits/char, parity, and stop bits */
  155.     kSERDInputBuffer            = 9,                            /* set buffer for chars received with no read pending */
  156.     kSERDSerHShake                = 10,                            /* equivalent to SerHShake, largely obsolete */
  157.     kSERDClearBreak                = 11,                            /* assert break signal on output */
  158.     kSERDSetBreak                = 12,                            /* negate break state on output */
  159.     kSERDBaudRate                = 13,                            /* set explicit baud rate, other settings unchanged */
  160.     kSERDHandshake                = 14,                            /* superset of 10, honors setting of fDTR */
  161.     kSERDClockMIDI                = 15,                            /* clock externally on CTS with specified multiplier */
  162.     kSERDMiscOptions            = 16,                            /* select clock source and DTR behavior on close */
  163.     kSERDAssertDTR                = 17,                            /* assert DTR output */
  164.     kSERDNegateDTR                = 18,                            /* negate DTR output */
  165.     kSERDSetPEChar                = 19,                            /* select char to replace chars with invalid parity */
  166.     kSERDSetPEAltChar            = 20,                            /* select char to replace char that replaces chars with invalid parity */
  167.     kSERDSetXOffFlag            = 21,                            /* set XOff output flow control (same as receiving XOff) */
  168.     kSERDClearXOffFlag            = 22,                            /* clear XOff output flow control (same as receiving XOn) */
  169.     kSERDSendXOn                = 23,                            /* send XOn if input flow control state is XOff */
  170.     kSERDSendXOnOut                = 24,                            /* send XOn regardless of input flow control state */
  171.     kSERDSendXOff                = 25,                            /* send XOff if input flow control state is XOn */
  172.     kSERDSendXOffOut            = 26,                            /* send XOff regardless of input flow control state */
  173.     kSERDResetChannel            = 27,                            /* reset serial I/O channel hardware */
  174.     kSERDHandshakeRS232            = 28,                            /* extension of 14, allows full RS-232 hardware handshaking */
  175.     kSERDStickParity            = 29,                            /* use mark/space parity */
  176.     kSERDAssertRTS                = 30,                            /* assert RTS output */
  177.     kSERDNegateRTS                = 31,                            /* negate RTS output */
  178.     kSERD115KBaud                = 115,                            /* set 115.2K baud data rate */
  179.     kSERD230KBaud                = 230                            /* set 230.4K baud data rate */
  180. };
  181.  
  182.  
  183. /* csCodes for serial driver Status routines */
  184.  
  185. enum {
  186.     kSERDInputCount                = 2,                            /* return characters available (SerGetBuf) */
  187.     kSERDStatus                    = 8,                            /* return characters available (SerStatus) */
  188.     kSERDVersion                = 9,                            /* return version number in first byte of csParam */
  189.     kSERDGetDCD                    = 256                            /* get instantaneous state of DCD (GPi) */
  190. };
  191.  
  192.  
  193.  
  194. struct SerShk {
  195.     Byte                             fXOn;                        /* XOn/XOff output flow control flag */
  196.     Byte                             fCTS;                        /* hardware output flow control flags */
  197.     unsigned char                     xOn;                        /* XOn character */
  198.     unsigned char                     xOff;                        /* XOff character */
  199.     Byte                             errs;                        /* errors mask bits */
  200.     Byte                             evts;                        /* event enable mask bits */
  201.     Byte                             fInX;                        /* XOn/XOff input flow control flag */
  202.     Byte                             fDTR;                        /* hardware input flow control flags */
  203. };
  204. typedef struct SerShk                    SerShk;
  205.  
  206. struct SerStaRec {
  207.     Byte                             cumErrs;                    /* errors accumulated since last SerStatus() call */
  208.     Byte                             xOffSent;                    /* input (requested to be) held off by xOffWasSent or dtrNegated or rtsNegated */
  209.     Byte                             rdPend;                        /* incomplete read pending in I/O queue */
  210.     Byte                             wrPend;                        /* incomplete write pending in I/O queue */
  211.     Byte                             ctsHold;                    /* transmit disabled by hardware handshaking */
  212.     Byte                             xOffHold;                    /* transmit disabled by XOn/XOff handshaking */
  213.     Byte                             dsrHold;                    /* transmit disabled: external device not ready */
  214.     Byte                             modemStatus;                /* reports modem status according to SerShk.evts */
  215. };
  216. typedef struct SerStaRec                SerStaRec;
  217. #if OLDROUTINENAMES
  218. /* ********************************************************************************************* */
  219. /* The following constant names have been retired in favor of standard, more descriptive names.  */
  220. /* You can still compile old code by defining OLDROUTINENAMES. There were several constants that */
  221. /* were formerly available that have been removed, as they are now regarded as either private or */
  222. /* unsupported. We advise that you stop using any constants that are not defined in this file.   */
  223. /* ********************************************************************************************* */
  224.  
  225. enum {
  226.     serdOptionClockExternal        = kOptionClockX1CTS,            /* option bit used with Control code 16 */
  227.     serdOptionPreserveDTR        = kOptionPreserveDTR            /* option bit used with Control code 16 */
  228. };
  229.  
  230. /* csCodes for serial driver Control routines */
  231.  
  232. enum {
  233.     serdReset                    = kSERDConfiguration,
  234.     serdSetBuf                    = kSERDInputBuffer,
  235.     serdHShake                    = kSERDSerHShake,
  236.     serdClrBrk                    = kSERDClearBreak,
  237.     serdSetBrk                    = kSERDSetBreak,
  238.     serdSetBaud                    = kSERDBaudRate,
  239.     serdHShakeDTR                = kSERDHandshake,
  240.     serdSetMIDI                    = kSERDClockMIDI,
  241.     serdSetMisc                    = kSERDMiscOptions,
  242.     serdSetDTR                    = kSERDAssertDTR,
  243.     serdClrDTR                    = kSERDNegateDTR,
  244.     serdSetPEChar                = kSERDSetPEChar,
  245.     serdSetPECharAlternate        = kSERDSetPEAltChar,
  246.     serdSetXOff                    = kSERDSetXOffFlag,
  247.     serdClrXOff                    = kSERDClearXOffFlag,
  248.     serdSendXOnConditional        = kSERDSendXOn,
  249.     serdSendXOn                    = kSERDSendXOnOut,
  250.     serdSendXOffConditional        = kSERDSendXOff,
  251.     serdSendXOff                = kSERDSendXOffOut,
  252.     serdChannelReset            = kSERDResetChannel,
  253.     serdSet230KBaud                = kSERD230KBaud                    /* set 230K baud data rate */
  254. };
  255.  
  256.  
  257. /* csCodes for serial driver Status routines */
  258.  
  259. enum {
  260.     serdGetBuf                    = kSERDInputCount,
  261.     serdStatus                    = kSERDStatus,
  262.     serdGetVers                    = kSERDVersion
  263. };
  264.  
  265. #endif  /* OLDROUTINENAMES */
  266.  
  267. /*
  268.     The following interfaces are for the legacy high-level serial driver glue in
  269.     the interface libraries of your development system. They merely substitue for
  270.     the corresponding synchronous calls to PBControl and PBStatus.
  271.  
  272.     They have not been updated as the serial driver API has evolved. Take note:
  273.  
  274.         SerHShake does not support hardware input flow control. Use csCode 14.
  275.         SerStatus returns only the first six bytes of SerStaRec (through xOffHold).
  276. */
  277. EXTERN_API( OSErr )
  278. SerReset                        (short                     refNum,
  279.                                  short                     serConfig);
  280.  
  281. EXTERN_API( OSErr )
  282. SerSetBuf                        (short                     refNum,
  283.                                  Ptr                     serBPtr,
  284.                                  short                     serBLen);
  285.  
  286. EXTERN_API( OSErr )
  287. SerHShake                        (short                     refNum,
  288.                                  const SerShk *            flags);
  289.  
  290. EXTERN_API( OSErr )
  291. SerSetBrk                        (short                     refNum);
  292.  
  293. EXTERN_API( OSErr )
  294. SerClrBrk                        (short                     refNum);
  295.  
  296. EXTERN_API( OSErr )
  297. SerGetBuf                        (short                     refNum,
  298.                                  long *                    count);
  299.  
  300. EXTERN_API( OSErr )
  301. SerStatus                        (short                     refNum,
  302.                                  SerStaRec *            serSta);
  303.  
  304.  
  305.  
  306.  
  307. #if PRAGMA_STRUCT_ALIGN
  308.     #pragma options align=reset
  309. #elif PRAGMA_STRUCT_PACKPUSH
  310.     #pragma pack(pop)
  311. #elif PRAGMA_STRUCT_PACK
  312.     #pragma pack()
  313. #endif
  314.  
  315. #ifdef PRAGMA_IMPORT_OFF
  316. #pragma import off
  317. #elif PRAGMA_IMPORT
  318. #pragma import reset
  319. #endif
  320.  
  321. #ifdef __cplusplus
  322. }
  323. #endif
  324.  
  325. #endif /* __SERIAL__ */
  326.  
  327.